<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>

<script>
  // 1.创建canvas画布
  const canvas = document.createElement("canvas");
  //  设置宽高
  canvas.width = 600;
  canvas.height = 400;
  document.body.append(canvas);

  //   2.获取画笔
  const context = canvas.getContext("2d");
  context.fillRect(100, 100, 150, 100);
</script>
